﻿using System;
using System.Windows.Forms;

using Pegasus.Diagnostics.Contracts;

namespace Pegasus.Windows.Forms
{
	/// <summary>
	/// This class is used to display an question (yes/no) box to the user.
	/// </summary>
	public static class YesNoBox
	{
		// Local Static Values
		private static string s_caption = "Question";

		/// <summary>
		/// Gets or sets the default caption.
		/// </summary>
		/// <value>The default caption.</value>
		public static string Caption
		{
			get
			{
				return s_caption;
			}

			set
			{
				Contract.Requires( !string.IsNullOrEmpty( value ), "Caption can not be null or empty" );

				s_caption = value;
			}
		}

		/// <summary>
		/// Shows the specified message in an question (yes/no) message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <returns>True is the user selected the Yes button; otherwise false.</returns>
		public static bool Show( string message )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );

			return Show( null, message, Caption );
		}

		/// <summary>
		/// Shows the specified message in an question (yes/no) message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <returns>True is the user selected the Yes button; otherwise false.</returns>
		public static bool Show( string message, string caption )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );
			Contract.Requires( !string.IsNullOrEmpty( caption ), "Caption can not be null or empty" );

			return Show( null, message, caption );
		}

		/// <summary>
		/// Shows the specified message in an question (yes/no) message box.
		/// </summary>
		/// <param name="parent">The parent window or form.</param>
		/// <param name="message">The message.</param>
		/// <returns>True is the user selected the Yes button; otherwise false.</returns>
		public static bool Show( IWin32Window parent, string message )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );

			return Show( parent, message, Caption );
		}

		/// <summary>
		/// Shows the specified message in an question (yes/no) message box.
		/// </summary>
		/// <param name="parent">The parent window or form.</param>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <returns>True is the user selected the Yes button; otherwise false.</returns>
		public static bool Show( IWin32Window parent, string message, string caption )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );
			Contract.Requires( !string.IsNullOrEmpty( caption ), "Caption can not be null or empty" );
			
			if( MessageBox.Show( parent, message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes )
			{
				return true;
			}

			return false;
		}
	}
}
